/*
 * ReadConsole.java
 *
 * Created on 13 novembre 2006, 13:49
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package ReadConsole;

import Exceptions.InputTypeException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 *
 * @author diaz
 */
public class ReadConsole {

    private static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

    public static int readInt() throws InputTypeException {
        try {
            return Integer.parseInt(stdin.readLine());
        } catch (Exception e) {
            throw new InputTypeException(0);
        }
    }

    public static String readString() throws InputTypeException {
        try {
            return stdin.readLine();
        } catch (Exception e) {
            throw new InputTypeException(1);
        }
    }

    public static float readFloat() throws InputTypeException {
        try {
            return Float.valueOf(stdin.readLine()).floatValue();
        } catch (Exception e) {
            throw new InputTypeException(2);
        }
    }

    public static double readDouble() throws InputTypeException {
        try {
            return Double.valueOf(stdin.readLine()).doubleValue();
        } catch (Exception e) {
            throw new InputTypeException(3);
        }
    }

    private static void errorOnInput(Exception e, String msg) {
        System.out.println("Error on reading: " + msg + ":" + e );
    }
}